var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("GameSceneMediator"),
    d = cc._decorator,
    u = d.ccclass,
    p = d.property,
    h = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.preload_prefabs = []),
                (t._moduleViewLayer = null),
                (t._popupViewLayer = null),
                (t._popMaskView = null),
                (t._moduleViewZIndex = 0),
                (t._popupViewZIndex = 1),
                (t._currModuleView = null),
                (t._catchModuleViews = []),
                (t._currDisplayPopupViews = []),
                (t._cachePopupViews = []),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                (this._moduleViewLayer = new cc.Node("_moduleViewLayer")),
                    this._moduleViewLayer.setContentSize(cc.size(cc.winSize.width, cc.winSize.height)),
                    (this._moduleViewLayer.zIndex = this._moduleViewZIndex),
                    (this._popupViewLayer = new cc.Node("_popupViewLayer")),
                    this._popupViewLayer.setContentSize(cc.size(cc.winSize.width, cc.winSize.height)),
                    (this._popupViewLayer.zIndex = this._popupViewZIndex),
                    (this._popMaskView = game.UIManager.instance.createNodeByPreloading(
                        c.default.Resources,
                        s.default.ResourceBundle.prefabs.assetsList.PopMaskView
                    )),
                    (this._popMaskView.active = !1),
                    this._popMaskView.setContentSize(cc.size(cc.winSize.width, cc.winSize.height)),
                    this._popupViewLayer.addChild(this._popMaskView),
                    this.node.addChild(this._moduleViewLayer),
                    this.node.addChild(this._popupViewLayer),
                    game.appFacade.registerMediator(new l.default(this));
                var e = this.node.getChildByName("hw_laoding");
                ad.curr_platform == window.ad.Platform.HUAWEI_GAME &&
                    ((e.zIndex = cc.macro.MAX_ZINDEX),
                    (e.active = !0),
                    this.scheduleOnce(function () {
                        e.active = !1;
                    }, 2));
            }),
            (t.prototype.start = function () {
                game.appFacade.startup();
            }),
            (t.prototype.replaceModuleView = function (e, t, o) {
                if ((void 0 === o && (o = null), this._currModuleView)) {
                    for (; this._currDisplayPopupViews.length > 0; ) {
                        var n = this._currDisplayPopupViews[this._currDisplayPopupViews.length - 1];
                        this.removePopupView(n.view, !1);
                    }
                    var i = this._currModuleView.view.getComponent(game.BaseComponent);
                    i && i.onRemoveToScene(),
                        this._currModuleView.view.getComponent(game.BaseComponent).isCache
                            ? ((this._currModuleView.view.active = !1),
                              (this._currModuleView.view.parent = null),
                              this._catchModuleViews.push({
                                  viewPath: this._currModuleView.viewPath,
                                  view: this._currModuleView.view
                              }))
                            : this._currModuleView.view.destroy();
                }
                for (var a = null, r = 0; r < this._catchModuleViews.length; r++)
                    (n = this._catchModuleViews[r]).viewPath === t &&
                        (((a = n.view).active = !0), this._catchModuleViews.splice(r, 1));
                if ((a || (a = game.UIManager.instance.createNodeByPreloading(e, t.toString())), a)) {
                    var s = a.getComponent(game.BaseComponent);
                    null !== s ? (s.param = o) : game.warn("replaceModuleView,the new view no extends BaseComponent"),
                        (this._currModuleView = {viewPath: t, view: a}),
                        this._moduleViewLayer.addChild(a);
                    var c = a.getComponent(game.BaseComponent);
                    c && c.onAddToScene();
                } else game.error("replaceModuleView final,the new view is null");
            }),
            (t.prototype.pushPopupView = function (e, t, o, n) {
                void 0 === t && (t = null), void 0 === o && (o = !1), void 0 === n && (n = !1);
                for (var i = null, a = 0; a < this._cachePopupViews.length; a++) {
                    var r = this._cachePopupViews[a];
                    r.name === e.name && (((i = r.view).active = !0), this._cachePopupViews.splice(a, 1));
                }
                if ((i || (i = game.UIManager.instance.createNodeByPreloading(c.default.Popup, e.assetsPath)), i)) {
                    var s = i.getComponent(game.BaseComponent);
                    null !== s ? (s.param = t) : game.warn("pushPopupView, new view no extends BaseComponent"),
                        this._popupViewLayer.addChild(i);
                    var l = i.getComponent(game.BaseComponent);
                    l && l.onAddToScene(),
                        this._currDisplayPopupViews.push({name: e.name, view: i, showMask: n}),
                        n &&
                            ((this._popMaskView.active = !0),
                            cc.Tween.stopAllByTarget(this._popMaskView),
                            cc.tween(this._popMaskView).to(0.1, {opacity: 255}).start()),
                        (i.opacity = 255),
                        (i.scale = 1),
                        o &&
                            ((i.opacity = 0),
                            this.scheduleOnce(function () {
                                (i.scale = 1.05),
                                    (i.active = !0),
                                    (i.opacity = 150),
                                    cc.Tween.stopAllByTarget(i),
                                    cc.tween(i).to(0.1, {scale: 1, opacity: 255}).start();
                            }));
                } else game.error("pushPopupView final,the new view is null");
            }),
            (t.prototype.removePopupView = function (e, t) {
                var o = this;
                void 0 === t && (t = !1);
                for (
                    var n = function (n) {
                            var a = i._currDisplayPopupViews[n];
                            if (a.view === e) {
                                i._currDisplayPopupViews.splice(n, 1);
                                var r = a.view.getComponent(game.BaseComponent),
                                    s = !1;
                                if ((r && r.isCache && (s = r.isCache), t))
                                    cc.Tween.stopAllByTarget(a.view),
                                        cc
                                            .tween(a.view)
                                            .to(0.2, {scale: 0.9, opacity: 0})
                                            .call(function () {
                                                var e = a.view.getComponent(game.BaseComponent);
                                                e && e.onRemoveToScene(),
                                                    s
                                                        ? ((a.view.active = !1), (a.view.parent = null))
                                                        : a.view.destroy();
                                            })
                                            .start(),
                                        i.checkAllShowMask() ||
                                            (cc.Tween.stopAllByTarget(i._popMaskView),
                                            cc
                                                .tween(i._popMaskView)
                                                .to(0.1, {opacity: 0})
                                                .call(function () {
                                                    o._popMaskView.active = !1;
                                                })
                                                .start());
                                else {
                                    var c = a.view.getComponent(game.BaseComponent);
                                    c && c.onRemoveToScene(),
                                        s ? ((a.view.active = !1), (a.view.parent = null)) : a.view.destroy(),
                                        i._popMaskView.active &&
                                            !i.checkAllShowMask() &&
                                            ((i._popMaskView.opacity = 0), (i._popMaskView.active = !1));
                                }
                                return s && i._cachePopupViews.push({name: a.name, view: a.view}), "break";
                            }
                        },
                        i = this,
                        a = 0;
                    a < this._currDisplayPopupViews.length && "break" !== n(a);
                    a++
                );
                this.scheduleOnce(function () {
                    o._currDisplayPopupViews.length <= 0 &&
                        o._popMaskView.active &&
                        (cc.Tween.stopAllByTarget(o._popMaskView),
                        cc
                            .tween(o._popMaskView)
                            .to(0.1, {opacity: 0})
                            .call(function () {
                                o._popMaskView.active = !1;
                            })
                            .start());
                });
            }),
            (t.prototype.checkAllShowMask = function () {
                for (var e = 0; e < this._currDisplayPopupViews.length; e++)
                    if (this._currDisplayPopupViews[e].showMask) return !0;
                return !1;
            }),
            r([p([cc.Prefab])], t.prototype, "preload_prefabs", void 0),
            r([u], t)
        );
    })(cc.Component);
i.default = h;
